home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 029a / fcopyc10.zip / COPYTEST.C < prev    next >
C/C++ Source or Header  |  1992-01-05  |  2KB  |  56 lines

  1. /*  This is a short program demonstrating the fcopy function.  It
  2.     prompts the user for source and target filenames and then performs
  3.     the copy.  If an error occurred during the copy operation, an error
  4.     message is displayed.
  5.  
  6.     Written by Ray Waters */
  7.  
  8. #include <io.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <errno.h>
  12. #include "fcopy.h"
  13.  
  14. main()
  15. {
  16.     char SrcName[80];                   /* buffer for source filename */
  17.     char DestName[80];                  /* buffer for target filename */
  18.     int input;
  19.  
  20.     printf("\nDemonstration of fcopy function:\n");
  21.  
  22.     do {
  23.         printf("\n  Enter the source file name:  ");
  24.         gets(SrcName);                      /* get source filename */
  25.  
  26.         input = access(SrcName, 0);         /* see if source exists */
  27.         if (input)
  28.             perror("\nINPUT ERROR");        /* if not, display error */
  29.     }
  30.     while (input);                          /* and try again */
  31.     strupr(SrcName);                        /* fold to upper case */
  32.  
  33.     printf("\n  Enter the target file name:  ");
  34.     gets(DestName);                         /* get target filename */
  35.     strupr(DestName);                       /* fold to upper case */
  36.  
  37.     if (!_fcopy(SrcName, DestName)) {       /* perform the file copy */
  38.                                             /* if successful, */
  39.         printf("\nSUCCESS: Copied %s to %s\n", SrcName, DestName);
  40.         return 0;                           /* exit */
  41.     }
  42.  
  43.     switch (errno) {        /* on error, display appropriate message */
  44.         case -1:
  45.             fprintf(stderr, "\nFCOPY ERROR: Target disk full\n");
  46.             break;
  47.         default:                    /* message depends upon errno */
  48.             perror("\nFCOPY ERROR");
  49.             break;
  50.     }
  51.     if (!remove(DestName))           /* try to delete bad target file */
  52.         printf("Target file %s deleted\n", DestName);
  53.  
  54.     return -1;                              /* exit */
  55. }
  56.